﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.WorkCenter_;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week1.Process_CRUD
{
    /// <summary>
    /// 获取工作中心分配资源表数据
    /// </summary>
    public class GetWorkCenterWealthHandler : IRequestHandler<GetWOrkCenterWealthCommand, Result>
    {
        public GetWorkCenterWealthHandler(IBaseRepository<WorkCenterWealth> workCenterWealthRepository)
        {
            WorkCenterWealthRepository = workCenterWealthRepository;
        }

        public IBaseRepository<WorkCenterWealth> WorkCenterWealthRepository { get; set; }
        public async Task<Result> Handle(GetWOrkCenterWealthCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCodes.Search};
            var sql = $"select * from workCentersWealth where WorkCenterId={request.ProcessId};";
            var WorkCenterWealthData = WorkCenterWealthRepository.GetAll(sql).ToList();
            if (WorkCenterWealthData != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = WorkCenterWealthData;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
